package com.cuit.jifver.weibo.db;

import android.content.Context;

final public class Database {
	
	private static Database mIntance;
	
	private DBHelper mDatabase;
	private Context mContent;

	public void setContent(Context c){
		mContent = c;
	}
	
	public Context getContent(){
		return mContent;
	}
	
	synchronized public static Database getInstance() {
		if (mIntance == null) {
			mIntance = new Database();
		}
		return mIntance;
	}

	public void clearInstance() {
		if (mDatabase != null){
			mDatabase.close();
			mDatabase = null;
		}
		mContent = null;
		mIntance = null;
	}
	
	public void createDatabase() throws RuntimeException{
		if (mContent != null){
			if (null == mDatabase){
				mDatabase = new DBHelper(mContent);
			}
		} else {
			throw new RuntimeException("DatabaseService ->mContent was null");
		}
	}
	
	public DBHelper db(){
		if (null == mDatabase){
			createDatabase();
		}
		return mDatabase; 
	}
}
